import { IMenuInfo, IMenuItem, IGetMenuListParams } from '@/types/menu'
import request from '@/utils/request'
import { AxiosPromise } from 'axios'
/**
 * 菜单列表
 * @param params
 * @returns
 */
function getMenuList(params?: IGetMenuListParams): AxiosPromise {
  return request({
    url: '/menu/list',
    method: 'get',
    params
  })
}

/**
 * 创建菜单
 * @param data
 * @returns
 */
function createMenu(data: IMenuInfo): AxiosPromise {
  return request({
    url: '/menu/create',
    method: 'post',
    data
  })
}

/**
 * 编辑菜单
 * @param data
 * @returns
 */
function editMenu(data: IMenuItem): AxiosPromise {
  return request({
    url: '/menu/edit',
    method: 'post',
    data
  })
}

/**
 * 删除菜单
 * @param id
 * @returns
 */
function deleteMenu(id: string): AxiosPromise {
  return request({
    url: '/menu/delete',
    method: 'post',
    data: { _id: id }
  })
}

export { getMenuList, createMenu, editMenu, deleteMenu }
